import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
//数据持久化
import persistedState from 'vuex-persistedstate'

export default new Vuex.Store({
  state: {
    // 购物车
    card: [],
    // 详情页
    shops: {}
  },
  mutations: {
  
  
    // 清空购物车
   
    //详情
    btnDetail(state, obj) {
      state.shops = obj
      console.log(obj);
    }
  },
  actions: {},
  plugins: [persistedState()],
  modules: {},
  getters: {
    // 数量
    nums(state) {
      var count = 0
      state.card.forEach(item => {
        count += item.number
      })
      return count
    },
    // 合计金额
    sums(state) {
      var sum = 0
      state.card.forEach(item => {
        sum += item.number * item.price
      })
      return sum
    }
  }
})